package com.yx.controller;

import com.yx.aop.annotation.LogRecord;
import com.yx.aop.enums.SysLogType;
import com.yx.aop.enums.SysLogUnit;
import com.yx.data.Result;
import com.yx.entity.SysUser;
import com.yx.page.Page;
import com.yx.service.SysUserService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.apache.shiro.authz.annotation.RequiresRoles;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
@RestController
@RequestMapping("sys/user")
public class SysUserController {
    @Autowired
    SysUserService sysUserService;

    /**
     * 拥有admin、leader角色或者sys:user:list权限的登陆用户可以访问
     * @param page
     * @param sysUser
     * @return
     */
    @GetMapping
    @RequiresRoles({"admin","leader"})
    @RequiresPermissions("sys:user:list")
    public Result getList(Page page, SysUser sysUser) {
        return sysUserService.getList(page,sysUser);
    }

    /**
     * 拥有sys:user:list权限的登陆用户可以访问
     * @param userId
     * @return
     */
    @GetMapping("/{userId}")
    @RequiresPermissions("sys:user:info")
    public Result getInfo(@PathVariable("userId") String userId) {
        return sysUserService.getInfo(userId);
    }
}
